﻿using Sidvall.Serialization;
using System.Linq;

namespace Sidvall.FileSystemManager.Data.Model.EntityManagers
{
    public sealed partial class RenameConfigManager<TEntity, TList> : global::Sidvall.Data.EntityManagerBase
        where TEntity : global::Sidvall.FileSystemManager.Data.IRenameConfig
        where TList : Sidvall.Data.IDataRowProvider<IRenameConfig>
    {
        #region Public Members

        #region AcceptChanges

        public void AcceptChanges(global::Sidvall.FileSystemManager.Data.IRenameConfig value)
        {
            AcceptChanges(value, null);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
        public void AcceptChanges(global::Sidvall.FileSystemManager.Data.IRenameConfig value, Sidvall.Data.AcceptChangesSettings acceptChangesSettings)
        {
            if (value == null)
                return;
            if (value.DataRowStateIsDirty)
            {
                if (acceptChangesSettings == null)
                    acceptChangesSettings = new Sidvall.Data.AcceptChangesSettings();
                Sidvall.Data.EntityManager.AcceptItemChanges(value, acceptChangesSettings);
            }
        }
        public void AcceptChanges(System.Collections.Generic.IEnumerable<global::Sidvall.FileSystemManager.Data.IRenameConfig> value)
        {
            AcceptItemsChanges(value, null);
        }
        public void AcceptChanges(System.Collections.Generic.IEnumerable<global::Sidvall.FileSystemManager.Data.IRenameConfig> value, Sidvall.Data.AcceptChangesSettings acceptChangesSettings)
        {
            AcceptItemsChanges(value, acceptChangesSettings);
        }

        #endregion
        #region SetBusinessSettings

        public void SetBusinessSettings(global::Sidvall.FileSystemManager.Data.IRenameConfig value, global::Sidvall.Business.BusinessSettings businessSettings, global::Sidvall.Business.BusinessCollectionSettings businessCollectionSettings)
        {
            if (value == null)
                return;
            var provider = value as global::Sidvall.Business.IBusinessSettingsProvider;
            if (provider != null)
                provider.BusinessSettings.Import(businessSettings);
        }
        public void SetBusinessSettings(System.Collections.Generic.IEnumerable<global::Sidvall.FileSystemManager.Data.IRenameConfig> value, global::Sidvall.Business.BusinessSettings businessSettings, global::Sidvall.Business.BusinessCollectionSettings businessCollectionSettings)
        {
            if (value == null)
                return;
            var provider = value as global::Sidvall.Business.IBusinessCollectionSettingsProvider;
            if (provider != null)
                provider.BusinessSettings.Import(businessCollectionSettings);
            foreach (var item in value)
                SetBusinessSettings(item, businessSettings, businessCollectionSettings);
        }

        #endregion
        #region GetDataRowStateCounts

        public global::Sidvall.Data.DataRowStateCountItemCollection GetDataRowStateCounts(global::Sidvall.FileSystemManager.Data.IRenameConfig value)
        {
            var items = new global::Sidvall.Data.DataRowStateCountItemCollection();
            LoadDataRowStateCounts(items, value);
            return items;
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
        internal void LoadDataRowStateCounts(global::Sidvall.Data.DataRowStateCountItemCollection items, global::Sidvall.FileSystemManager.Data.IRenameConfig value)
        {
            if (value == null)
                return;
            items.Add(global::Sidvall.FileSystemManager.Data.Model.DomainObjects.RenameConfig, value);
        }
        public global::Sidvall.Data.DataRowStateCountItemCollection GetDataRowStateCounts(System.Collections.Generic.IEnumerable<global::Sidvall.FileSystemManager.Data.IRenameConfig> value)
        {
            var items = new global::Sidvall.Data.DataRowStateCountItemCollection();
            LoadDataRowStateCounts(items, value);
            return items;
        }
        internal void LoadDataRowStateCounts(global::Sidvall.Data.DataRowStateCountItemCollection items, System.Collections.Generic.IEnumerable<global::Sidvall.FileSystemManager.Data.IRenameConfig> value)
        {
            if (value == null)
                return;
            items.Add(global::Sidvall.FileSystemManager.Data.Model.DomainObjects.RenameConfig, value as Sidvall.Data.IListContextProvider);
            foreach (var item in value)
                LoadDataRowStateCounts(items, item);
        }

        #endregion
        #region LoadInstanceField

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public void LoadInstanceField(System.Collections.Generic.IEnumerable<global::Sidvall.FileSystemManager.Data.IRenameConfig> items, string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            if (items == null)
                return;
            foreach (var item in items)
                LoadInstanceField(item, fieldName, value, cascade, raisePropertyChanged, updateState);
        }
        partial void OnAfterLoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState);
        partial void OnBeforeLoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState);
        partial void OnLoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "cascade"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")]
        public void LoadInstanceField(global::Sidvall.FileSystemManager.Data.IRenameConfig item, string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            if (item == null)
                return;
            if (fieldName == null)
                return;
            OnBeforeLoadInstanceField(fieldName, value, cascade, raisePropertyChanged, updateState);
            switch (fieldName)
            {
                case "CaseSensitive":
                    if (value == null)
                        return;
                    item.CaseSensitive = (bool)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "CaseSensitive", raisePropertyChanged, updateState);
                    break;
                case "FolderPath":
                    value = Sidvall.Business.ValidationManager.GetValidString(value, false, null, true);
                    item.FolderPath = (string)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "FolderPath", raisePropertyChanged, updateState);
                    break;
                case "NewName1":
                    value = Sidvall.Business.ValidationManager.GetValidString(value, false, null, true);
                    item.NewName1 = (string)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "NewName1", raisePropertyChanged, updateState);
                    break;
                case "NewName2":
                    value = Sidvall.Business.ValidationManager.GetValidString(value, false, null, true);
                    item.NewName2 = (string)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "NewName2", raisePropertyChanged, updateState);
                    break;
                case "NewName3":
                    value = Sidvall.Business.ValidationManager.GetValidString(value, false, null, true);
                    item.NewName3 = (string)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "NewName3", raisePropertyChanged, updateState);
                    break;
                case "OldName1":
                    value = Sidvall.Business.ValidationManager.GetValidString(value, false, null, true);
                    item.OldName1 = (string)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "OldName1", raisePropertyChanged, updateState);
                    break;
                case "OldName2":
                    value = Sidvall.Business.ValidationManager.GetValidString(value, false, null, true);
                    item.OldName2 = (string)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "OldName2", raisePropertyChanged, updateState);
                    break;
                case "OldName3":
                    value = Sidvall.Business.ValidationManager.GetValidString(value, false, null, true);
                    item.OldName3 = (string)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "OldName3", raisePropertyChanged, updateState);
                    break;
                case "RecursiveFolders":
                    if (value == null)
                        return;
                    item.RecursiveFolders = (bool)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "RecursiveFolders", raisePropertyChanged, updateState);
                    break;
                case "RenameConfigId":
                    value = Sidvall.Business.ValidationManager.GetValidInt32(value, null, null);
                    item.RenameConfigId = (System.Nullable<int>)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "RenameConfigId", raisePropertyChanged, updateState);
                    break;
                case "RenameFiles":
                    if (value == null)
                        return;
                    item.RenameFiles = (bool)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "RenameFiles", raisePropertyChanged, updateState);
                    break;
                case "RenameFolders":
                    if (value == null)
                        return;
                    item.RenameFolders = (bool)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "RenameFolders", raisePropertyChanged, updateState);
                    break;
                case "SearchPatterns":
                    value = Sidvall.Business.ValidationManager.GetValidString(value, false, null, true);
                    item.SearchPatterns = (string)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "SearchPatterns", raisePropertyChanged, updateState);
                    break;
                case "UpdateFileContents":
                    if (value == null)
                        return;
                    item.UpdateFileContents = (bool)value;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "UpdateFileContents", raisePropertyChanged, updateState);
                    break;
                default:
                    OnLoadInstanceField(fieldName, value, cascade, raisePropertyChanged, updateState);
                    break;
            }
            OnAfterLoadInstanceField(fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region Clone

        public TEntity Clone(IRenameConfig value)
        {
            return Copy(value, Sidvall.Data.CopySettings.Clone());
        }
        public TList Clone(System.Collections.Generic.IEnumerable<IRenameConfig> value)
        {
            return Copy(value, Sidvall.Data.CopySettings.Clone());
        }

        #endregion
        #region Copy

        public TEntity Copy(IRenameConfig value)
        {
            return Copy(value, null, string.Empty, string.Empty);
        }
        public TEntity Copy(IRenameConfig value, Sidvall.Data.CopySettings copySettings)
        {
            return Copy(value, copySettings, string.Empty, string.Empty);
        }
        internal TEntity Copy(IRenameConfig value, Sidvall.Data.CopySettings copySettings, string parent, string child)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(value, copySettings.RowFilter))
                return default(TEntity);
            var item = (TEntity)this.EntityFacadeManager.ResourceFactory.CreateItem(global::Sidvall.FileSystemManager.Data.Model.DomainObjects.RenameConfig, null);
            if (item == null)
                return default(TEntity);
            Import(item, value, copySettings, parent, child);
            return item;
        }

        public TList Copy(System.Collections.Generic.IEnumerable<IRenameConfig> value)
        {
            return Copy(value, null, string.Empty, string.Empty);
        }
        public TList Copy(System.Collections.Generic.IEnumerable<IRenameConfig> value, Sidvall.Data.CopySettings copySettings)
        {
            return Copy(value, copySettings, string.Empty, string.Empty);
        }
        internal TList Copy(System.Collections.Generic.IEnumerable<IRenameConfig> value, Sidvall.Data.CopySettings copySettings, string parent, string child)
        {
            var items = (TList)this.EntityFacadeManager.ResourceFactory.CreateItems(global::Sidvall.FileSystemManager.Data.Model.DomainObjects.RenameConfig);
            Import(items, value, copySettings, parent, child);
            return items;
        }

        #endregion
        #region GetKey

        public string GetKey(IRenameConfig item)
        {
            if (item == null)
                return null;
            if (item.RenameConfigId == null)
                return null;
            return item.RenameConfigId.ToString();
        }
        public string GetKey(int renameConfigId)
        {
            return renameConfigId.ToString(System.Globalization.CultureInfo.InvariantCulture);
        }
        public string GetKey(Sidvall.Data.Filter<global::Sidvall.FileSystemManager.Data.Fields.RenameConfigField> item)
        {
            if (item == null)
                return null;
            var part = item.FilterItems.GetFilterItemValue(Sidvall.FileSystemManager.Data.Fields.RenameConfigField.RenameConfigId, null);
            if (part == null)
                return null;
            var value = part;
            return value;
        }

        #endregion
        #region ParseKey

        public System.Nullable<int> ParseKey(string key)
        {
            return key.ToNullableInt32();
        }

        #endregion
        #region GetResources

        public Sidvall.Security.ResourceItemCollection GetResources(IRenameConfig value, System.Collections.Generic.IEnumerable<string> actions)
        {
            var items = new Sidvall.Security.ResourceItemCollection();
            LoadResources(items, value, actions, false);
            return items;
        }
        public Sidvall.Security.ResourceItemCollection GetResources(System.Collections.Generic.IEnumerable<IRenameConfig> values, System.Collections.Generic.IEnumerable<string> actions)
        {
            var items = new Sidvall.Security.ResourceItemCollection();
            LoadResources(items, values, actions, false);
            return items;
        }
        internal void LoadResources(Sidvall.Security.ResourceItemCollection items, IRenameConfig value, System.Collections.Generic.IEnumerable<string> actions, bool addResources)
        {
            if (value == null)
                return;
            if (addResources)
                items.AddRange(new string[] { Sidvall.FileSystemManager.Data.Model.DomainObjects.RenameConfig }, actions);
        }
        internal void LoadResources(Sidvall.Security.ResourceItemCollection items, System.Collections.Generic.IEnumerable<IRenameConfig> values, System.Collections.Generic.IEnumerable<string> actions, bool addResources)
        {
            if (values == null)
                return;
            if (addResources)
                items.AddRange(new string[] { Sidvall.FileSystemManager.Data.Model.DomainObjects.RenameConfig }, actions);
            foreach (var value in values)
                LoadResources(items, value, actions, false);
        }

        public Sidvall.Security.ResourceItemCollection GetResources(global::Sidvall.FileSystemManager.Data.Relations.RenameConfigRelation relation, System.Collections.Generic.IEnumerable<string> actions)
        {
            var items = new Sidvall.Security.ResourceItemCollection();
            switch (relation)
            {
                default:
                    break;
            }
            return items;
        }
        public Sidvall.Security.ResourceItemCollection GetResources(System.Collections.Generic.IEnumerable<global::Sidvall.FileSystemManager.Data.Relations.RenameConfigRelation> relations, System.Collections.Generic.IEnumerable<string> actions)
        {
            if (relations == null)
                return null;
            var items = new Sidvall.Security.ResourceItemCollection();
            foreach (var relation in relations)
            {
                var resources = GetResources(relation, actions);
                items.AddRange(resources);
            }
            return items;
        }

        #endregion
        #region Import

        public void Import(TEntity destination, IRenameConfig source)
        {
            Import(destination, source, null, string.Empty, string.Empty);
        }
        public void Import(TEntity destination, IRenameConfig source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source, copySettings, string.Empty, string.Empty);
        }
        partial void OnAfterImport(TEntity destination, IRenameConfig source, Sidvall.Data.CopySettings copySettings, string parent, string child);
        partial void OnBeforeImport(TEntity destination, IRenameConfig source, Sidvall.Data.CopySettings copySettings, ref string parent, ref string child);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "parent"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "child"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        internal void Import(TEntity destination, IRenameConfig source, Sidvall.Data.CopySettings copySettings, string parent, string child)
        {
            if (destination == null)
                return;
            if (source == null)
                return;
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            OnBeforeImport(destination, source, copySettings, ref parent, ref child);
            if ((copySettings.FieldOption & Sidvall.Business.FieldCopyOptions.AutomaticPrimaryKeys) == Sidvall.Business.FieldCopyOptions.AutomaticPrimaryKeys)
            {
                destination.RenameConfigId = source.RenameConfigId;
            }
            if ((copySettings.FieldOption & Sidvall.Business.FieldCopyOptions.ManualNonPrimaryKeys) == Sidvall.Business.FieldCopyOptions.ManualNonPrimaryKeys)
            {
                destination.CaseSensitive = source.CaseSensitive;
                destination.FolderPath = source.FolderPath;
                destination.NewName1 = source.NewName1;
                destination.NewName2 = source.NewName2;
                destination.NewName3 = source.NewName3;
                destination.OldName1 = source.OldName1;
                destination.OldName2 = source.OldName2;
                destination.OldName3 = source.OldName3;
                destination.RecursiveFolders = source.RecursiveFolders;
                destination.RenameFiles = source.RenameFiles;
                destination.RenameFolders = source.RenameFolders;
                destination.SearchPatterns = source.SearchPatterns;
                destination.UpdateFileContents = source.UpdateFileContents;
            }
            Sidvall.Data.EntityManager.AfterImportItem(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings, parent, child);
        }

        public void Import(System.Collections.Generic.IEnumerable<IRenameConfig> destination, System.Collections.Generic.IEnumerable<IRenameConfig> source)
        {
            Import(destination, source, null, string.Empty, string.Empty);
        }
        public void Import(System.Collections.Generic.IEnumerable<IRenameConfig> destination, System.Collections.Generic.IEnumerable<IRenameConfig> source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source, copySettings, string.Empty, string.Empty);
        }
        public void Import(System.Collections.Generic.IEnumerable<IRenameConfig> destination, System.Collections.Generic.IEnumerable<IRenameConfig> source, long? totalRowCount, Sidvall.Data.CopySettings copySettings)
        {
            Sidvall.Data.ITotalRowCount rowCountProvider;

            if (source == null)
                return;
            Import(destination, source, copySettings, string.Empty, string.Empty);
            if (totalRowCount != null)
            {
                rowCountProvider = destination as Sidvall.Data.ITotalRowCount;
                if (rowCountProvider != null)
                    rowCountProvider.TotalRowCount = totalRowCount.Value;
            }
        }
        internal void Import(Sidvall.Data.IDataRowProvider<IRenameConfig> destination, System.Collections.Generic.IEnumerable<IRenameConfig> source, Sidvall.Data.CopySettings copySettings, string parent, string child)
        {
            Import(destination.DataItems, source, copySettings, parent, child);
        }
        partial void OnBeforeImport(System.Collections.Generic.IEnumerable<IRenameConfig> destination, System.Collections.Generic.IEnumerable<IRenameConfig> source, Sidvall.Data.CopySettings copySettings, string parent, string child);
        partial void OnAfterImport(System.Collections.Generic.IEnumerable<IRenameConfig> destination, System.Collections.Generic.IEnumerable<IRenameConfig> source, Sidvall.Data.CopySettings copySettings, string parent, string child);
        internal void Import(System.Collections.Generic.IEnumerable<IRenameConfig> destination, System.Collections.Generic.IEnumerable<IRenameConfig> source, Sidvall.Data.CopySettings copySettings, string parent, string child)
        {
            OnBeforeImport(destination, source, copySettings, parent, child);
            ImportItems(destination, source, copySettings, parent, child);
            OnAfterImport(destination, source, copySettings, parent, child);
        }

        #endregion
        #region DataRowIsValid

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        public bool DataRowIsValid(IRenameConfig value, Sidvall.Data.BusinessRuleFilter filter)
        {
            if (value == null)
                return true;
            if (filter == null)
                filter = Sidvall.Data.BusinessRuleFilter.CreateFilter();
            var provider = value as Sidvall.Data.IValidParentProvider;
            if ((provider != null) && (!provider.IsSelfValid(filter)))
                return false;
            return true;
        }
        public bool DataRowIsValid(System.Collections.Generic.IEnumerable<IRenameConfig> value, Sidvall.Data.BusinessRuleFilter filter)
        {
            if (value == null)
                return true;
            foreach (var item in value)
            {
                if (!DataRowIsValid(item, filter))
                    return false;
            }
            return true;
        }

        #endregion
        #region DataRowStateIsDirty

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        public bool DataRowStateIsDirty(IRenameConfig value)
        {
            if (value == null)
                return false;
            if (value.DataRowStateIsSelfDirty)
                return true;
            return false;
        }
        public bool DataRowStateIsDirty(System.Collections.Generic.IEnumerable<IRenameConfig> value)
        {
            return IsDirtyItems(value);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(IRenameConfig value)
        {
            return await ValidateAsync(value, (Sidvall.Data.ValidationSettings)null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(IRenameConfig value, Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await ValidateAsync(value, context).ConfigureAwait(false);
            return context.AllBusinessRules;
        }
        partial void OnBeforeValidate(IRenameConfig value, Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        partial void OnAfterValidate(IRenameConfig value, Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        public async System.Threading.Tasks.Task ValidateAsync(IRenameConfig value, Sidvall.Business.ValidationContext context)
        {
            if (value == null)
                return;
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnBeforeValidate(value, itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync().ConfigureAwait(false);
            OnAfterValidate(value, itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync().ConfigureAwait(false);
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = value as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.Merge(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(System.Collections.Generic.IEnumerable<IRenameConfig> value)
        {
            return await ValidateAsync(value, (Sidvall.Data.ValidationSettings)null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(System.Collections.Generic.IEnumerable<IRenameConfig> value, Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await ValidateAsync(value, context).ConfigureAwait(false);
            return context.AllBusinessRules;
        }
        public async System.Threading.Tasks.Task ValidateAsync(System.Collections.Generic.IEnumerable<IRenameConfig> value, Sidvall.Business.ValidationContext context)
        {
            if (value == null)
                return;
            foreach (var item in value)
                await ValidateAsync(item, context).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize(IRenameConfig value)
        {
            Initialize(value, null);
        }
        partial void OnAfterInitialize(IRenameConfig value);
        partial void OnBeforeInitialize(IRenameConfig value);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public void Initialize(IRenameConfig value, Sidvall.Data.InitializeSettings settings)
        {
            if (value == null)
                return;
            if (settings == null)
                settings = new Sidvall.Data.InitializeSettings();
            OnBeforeInitialize(value);
            switch (settings.FieldOption)
            {
                case Sidvall.Data.FieldInitializeOption.Reset:
                    value.CaseSensitive = false;
                    value.FolderPath = string.Empty;
                    value.NewName1 = string.Empty;
                    value.NewName2 = string.Empty;
                    value.NewName3 = string.Empty;
                    value.OldName1 = string.Empty;
                    value.OldName2 = string.Empty;
                    value.OldName3 = string.Empty;
                    value.RecursiveFolders = false;
                    value.RenameConfigId = null;
                    value.RenameFiles = false;
                    value.RenameFolders = false;
                    value.SearchPatterns = string.Empty;
                    value.UpdateFileContents = false;
                    break;
                case Sidvall.Data.FieldInitializeOption.Validate:
                    value.FolderPath = Sidvall.Business.ValidationManager.GetValidString(value.FolderPath, false, null, true);
                    value.NewName1 = Sidvall.Business.ValidationManager.GetValidString(value.NewName1, false, null, true);
                    value.NewName2 = Sidvall.Business.ValidationManager.GetValidString(value.NewName2, false, null, true);
                    value.NewName3 = Sidvall.Business.ValidationManager.GetValidString(value.NewName3, false, null, true);
                    value.OldName1 = Sidvall.Business.ValidationManager.GetValidString(value.OldName1, false, null, true);
                    value.OldName2 = Sidvall.Business.ValidationManager.GetValidString(value.OldName2, false, null, true);
                    value.OldName3 = Sidvall.Business.ValidationManager.GetValidString(value.OldName3, false, null, true);
                    value.RenameConfigId = Sidvall.Business.ValidationManager.GetValidInt32(value.RenameConfigId, null, null);
                    value.SearchPatterns = Sidvall.Business.ValidationManager.GetValidString(value.SearchPatterns, false, null, true);
                    break;
                default:
                    break;
            }
            if (settings.ClearBusinessRules)
            {
                var businessRulesProvider = value as Sidvall.Data.IBusinessRulesProvider;
                if (businessRulesProvider != null)
                    businessRulesProvider.BusinessRules.Clear();
            }
            OnAfterInitialize(value);
        }
        public void Initialize(System.Collections.Generic.IEnumerable<IRenameConfig> value)
        {
            Initialize(value, null);
        }
        public void Initialize(System.Collections.Generic.IEnumerable<IRenameConfig> value, Sidvall.Data.InitializeSettings settings)
        {
            InitializeItems(value, settings);
        }

        #endregion
        #region EntityManagerBase Members

        protected override Sidvall.Data.IDataRowContextProvider CopyItem(Sidvall.Data.IDataRowContextProvider destination, Sidvall.Data.CopySettings copySettings, string parent, string child)
        {
            return Copy(destination as IRenameConfig, copySettings, parent, child);
        }
        protected override void ImportItem(Sidvall.Data.IDataRowContextProvider destination, Sidvall.Data.IDataRowContextProvider source, Sidvall.Data.CopySettings copySettings, string parent, string child)
        {
            Import((TEntity)destination, source as IRenameConfig, copySettings, parent, child);
        }
        protected override void AcceptItemChanges(Sidvall.Data.IDataRowContextProvider item, Sidvall.Data.AcceptChangesSettings acceptChangesSettings)
        {
            AcceptChanges(item as IRenameConfig, acceptChangesSettings);
        }
        protected override bool IsDirtyItem(Sidvall.Data.IDataRowContextProvider item)
        {
            return DataRowStateIsDirty(item as IRenameConfig);
        }
        protected override void InitializeItem(Sidvall.Data.IDataRowContextProvider item, Sidvall.Data.InitializeSettings settings)
        {
            Initialize(item as IRenameConfig, settings);
        }

        #endregion

        #endregion
        #region Private Members

        private global::Sidvall.FileSystemManager.Data.Model.IEntityFacadeManager EntityFacadeManager { get; set; }

        #endregion
        #region Constructors

        public RenameConfigManager(global::Sidvall.FileSystemManager.Data.Model.IEntityFacadeManager entityFacadeManager)
        {
            this.EntityFacadeManager = entityFacadeManager;
        }

        #endregion
    }
}